home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / VAP2VOX.ZIP / vap2vox.c next >
C/C++ Source or Header  |  1994-11-06  |  2KB  |  84 lines

  1. /* VAP2VOX - Translate .VAP file to library of .VOX files 5-27-88/IHM */
  2.  
  3. /* VAP2VOX <filename[.VAP]> [<optional offset>] */
  4.  
  5. #include <stdio.h>
  6. #include <ctype.h>
  7. #include "vapdir.h"
  8.  
  9. #define    BUFSIZE    2048
  10.  
  11. extern errno;
  12.  
  13. char outfname[16];
  14. FILE *infp, *outfp;
  15. unsigned int msg_offset = 0;        /* Default 0 offset */
  16.  
  17. VAPDIRHDR dirhead;
  18. VAPENTRY *dirptr;
  19.  
  20. char msgbuf[BUFSIZE];
  21.  
  22. main (argc, argv)
  23. int argc;
  24. char **argv;
  25.    {
  26.     long i, j, k, l, m, n;
  27.  
  28.     if (argc < 2)
  29.         error("usage: %s filename[.VAP] [<offset>]\n", argv[0]);
  30.  
  31.     if (!(infp = fopen(argv[1], "r+b")))
  32.         error("%s: input file '%s' doesn't exist\n", argv[0], argv[1]);
  33.     if (argc > 2)
  34.        {
  35.         if (!isdigit(argv[2][0]))
  36.             error("%s: nonnumeric offset specified\n", argv[0]);
  37.  
  38.         msg_offset = atoi(argv[2]);
  39.        }
  40.     /* For now, we assume that if we got this far, the file is vaild */
  41.     fread(&dirhead, sizeof(dirhead), 1, infp);    /* Suck in header */
  42.  
  43.     /* Allocate memory for retrieval table */
  44.     dirptr = (VAPENTRY *) malloc(dirhead.max_prompts * sizeof(VAPENTRY));
  45.  
  46.     /* Read in retrieval table */
  47.     fread(dirptr, sizeof(VAPENTRY), dirhead.max_prompts, infp);
  48.  
  49.     printf("%ld prompt%s\n",dirhead.total_prompts, dirhead.total_prompts==1?"":"s");
  50.         for (l = 0; l < dirhead.total_prompts; ++l)
  51.        {
  52.         if (!dirptr[l].length)
  53.            {
  54.             printf("0 length message %ld - skipping\n", l+1);
  55.             continue;
  56.            }
  57.         fseek(infp, dirptr[l].start, SEEK_SET);    /* Seek to speech */
  58.         sprintf(outfname, "msg%d.vox", msg_offset++);
  59.         if (!(outfp = fopen(outfname, "w+b")))
  60.             error("%s: can't open output file - error %d\n", argv[0], errno);
  61.         for (n = 0, j = BUFSIZE; j == BUFSIZE;)
  62.            {
  63.             if ((i = dirptr[l].length - n) < j)
  64.                 j = i;
  65.             j = fread(msgbuf, 1, j, infp);
  66.             if (fwrite(msgbuf, 1, j, outfp) != j)
  67.                 error("%s: file write error %d\n", argv[0], errno);
  68.             n += j;
  69.  
  70.            }
  71.         fclose(outfp);
  72.         printf("%s - %ld bytes written\n", outfname, n);
  73.        }
  74.    }
  75.  
  76.  
  77. error (template, arg1, arg2, arg3, arg4)
  78. char *template;
  79. int arg1, arg2, arg3, arg4;
  80.    {
  81.     fprintf(stderr, template, arg1, arg2, arg3, arg4);
  82.     exit(1);
  83.    }
  84.